<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla modellist library
jimport('joomla.application.component.modellist');

/**
 * Cart Model
 */
class ProductModelCart extends JModelList
{
	/**
	 * @var array products
	 */
	protected $products;
	
	/**
	 * Get Items
	 */
	public function getItems() {
		$session = JFactory::getSession();
		$cart = $session->get("cart");
		$items = array();
		if (isset($cart)) {
			$db	= $this->getDbo();
			foreach ($cart as $item) {
				$id = $item['id'];
				if (!isset($this->products[$id])) {
					$query= $db->getQuery(true);
					$query->select('*');
					$query->from('#__product');
					$query->where('id = ' . $id);
					$db->setQuery($query);
					if ($res = $db->loadObject()) {
						// Assign the message
						$this->products[$id] = $res;

						$items[] = array('id'   => $id,
										 'data' => $res,
										 'qty'  => $item['qty']);
					}
				}
			}
		}
		return $items;
	}
}